package com.ys;

import java.util.List;
import java.util.Map;

/**
 * @program: note
 * @description:
 * @author:
 * @create 2020-06-11 22:07
 **/
public class ConsumeRecordController {
    private ConsumeRecordService consumeRecordService = new ConsumeRecordServiceImpl();

    public void save(String time, String name, Double price, Integer num, String type) {
        ConsumeRecord record = ConsumeRecordMapper.createRecord(time, name, price, num, type);
        consumeRecordService.save(record);
    }

    // 总消费
    public String getTotalCostBetweenTime(String startTime, String endTime) {
        return "" + consumeRecordService.getTotalCostBetweenTime(startTime, endTime);
    }

    // 名称
    public String getNameCostBetweenTime(String startTime, String endTime) {
        Map<String, Double> map = consumeRecordService.getNameCostMapBetweenTime(startTime, endTime);
        StringBuilder stringBuilder = new StringBuilder();
        for (Map.Entry<String, Double> entry : map.entrySet()) {
            stringBuilder.append(entry.getKey()).append("\t").append(entry.getValue()).append("\n");
        }
        return stringBuilder.toString();
    }

    // 最多消费物品
    public String getMostCostBetweenTime(String startTime, String endTime) {
        ConsumeNameDetail detail = consumeRecordService.getMostCostDetail(startTime, endTime);
        return detail.toString();
    }

    // 类型
    public String getTypeCostBetweenTime(String startTime, String endTime) {
        Map<String, ConsumeTypeDetail> map = consumeRecordService.getTypeCostMapBetween(startTime, endTime);
        StringBuilder stringBuilder = new StringBuilder();
        for (Map.Entry<String, ConsumeTypeDetail> entry : map.entrySet()) {
            stringBuilder.append(entry.getValue().toString()).append("\n");
        }
        return stringBuilder.toString();
    }
}
